package com.hunttown.mes.impl;

import com.hunttown.mes.rpc.api.TransactionRpcService;
import com.hunttown.mes.service.TransactionManagerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * created by wangjunfu on 2020-05-08
 */
@Service
public class TransactionRpcServiceImpl implements TransactionRpcService {
    private final Logger logger = LoggerFactory.getLogger(TransactionRpcServiceImpl.class);

    private final TransactionManagerService transactionManagerService;

    @Autowired
    public TransactionRpcServiceImpl(TransactionManagerService transactionManagerService) {
        this.transactionManagerService = transactionManagerService;
    }

    @Override
    public Integer createApplyWithout(String businessName, String tableName, Integer recordId, Integer createPeople, Map<String, String> map) {
        try {
            return transactionManagerService.createApplyWithout(businessName, tableName, recordId, createPeople, map);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public Boolean insertWfLine(Integer businessId, Integer applyId, Integer createPeople, Map<String, String> map) {
        try {
            return transactionManagerService.insertWfLine(businessId, applyId, createPeople, map);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void setExector(Integer applyId, Map<Integer, Integer> replaceMap) {
        try {
            transactionManagerService.setExector(applyId, replaceMap);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void setManageApply(Integer applyId, Integer nodeSort, Integer isAuto) {
        try {
            transactionManagerService.setManageApply(applyId, nodeSort, isAuto);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public Boolean approvelApply(Integer id, Integer status, String remark, Integer approvel, Integer addApprove, Integer backLineId) {
        try {
            return transactionManagerService.approvelApply(id, status, remark, approvel, addApprove, backLineId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void autoApply(Integer businessId, Integer applyId, Integer nodeSign, Integer adminId) {
        try {
            transactionManagerService.autoApply(businessId, applyId, nodeSign, adminId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void autoApply(Integer businessId, Integer applyId, Integer nodeSign, String remark, Integer adminId) {
        try {
            transactionManagerService.autoApply(businessId, applyId, nodeSign, remark, adminId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void autoApplyFirstNode(Integer applyId, Integer status, Integer adminId) {
        try {
            transactionManagerService.autoApplyFirstNode(applyId, status, adminId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void autoApplyCurrNode(Integer applyId, Integer status, Integer adminId) {
        try {
            transactionManagerService.autoApplyCurrNode(applyId, status, adminId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
